/** @format */

import React from 'react';
import Snackbar from '@material-ui/core/Snackbar';
import MuiAlert from '@material-ui/lab/Alert';

interface IOnClose {
  (): void;
}

interface IProps {
  autoHideDuration?: number;
  open?: boolean;
  vertical?: 'top' | 'bottom';
  horizontal?: 'left' | 'center' | 'right';
  msg: string;
  severity?: 'error' | 'warning' | 'info' | 'success';
  onClose: IOnClose;
}

class AlertDialog extends React.Component<IProps> {
  constructor(props: IProps) {
    super(props);
  }

  //autocomplete="off"
  render(): JSX.Element {
    return (
      <Snackbar
        anchorOrigin={{
          vertical: this.props.vertical || 'top',
          horizontal: this.props.horizontal || 'center',
        }}
        open={this.props.open || false}
        autoHideDuration={this.props.autoHideDuration || 3000}
        onClose={this.props.onClose}>
        <MuiAlert elevation={6} variant="filled" onClose={this.props.onClose} severity={this.props.severity}>
          {this.props.msg}
        </MuiAlert>
      </Snackbar>
    );
  }
}

export default AlertDialog;
